﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using CoreEx.Common.Linq;
using LinFu.IoC.Configuration;

namespace CoreEx.Database.Linq.Implementation
{
    [Implements(typeof(IQueryableResolver))]
    public class QueryableResolver : ExpressionVisitor,IQueryableResolver
    {
        private IQueryable _queryableTarget;
        public IQueryable ResolveFrom(Expression expression)
        {
            Visit(expression);
            return _queryableTarget;
        }

        protected override Expression VisitConstant(ConstantExpression c)
        {
            var queryable = c.Value as IQueryable;
            if (queryable != null)
                _queryableTarget = queryable;
            return base.VisitConstant(c);
        }

    }
}
